/* Copyright  2009
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 * @filename:  sql_error.h
 */

#ifndef __SQL_ERROR_H__
#define __SQL_ERROR_H__

#include <sql_alloc.h>

class Session ;
typedef struct st_lex_string LEX_STRING;
class COLLAPSAR_ERROR: public Sql_alloc
{
public:
  enum enum_warning_level
  {
    WARN_LEVEL_NOTE,
    WARN_LEVEL_WARN,
    WARN_LEVEL_ERROR,
    WARN_LEVEL_END
  };

  uint32_t code;
  enum_warning_level level;
  char *   msg ;

  COLLAPSAR_ERROR(Session *session, uint32_t code_arg,
                      enum_warning_level level_arg,
	                    const char *msg_arg)
                      :code(code_arg), level(level_arg)
  {
    if (msg_arg)
      set_msg(session, msg_arg);
  }
  void set_msg(Session *session, const char *msg_arg);
};

COLLAPSAR_ERROR *push_warning(Session *session,
                                  COLLAPSAR_ERROR::enum_warning_level level,
                                  uint32_t code,
                                  const char *msg);
void push_warning_printf(Session *session,
                         COLLAPSAR_ERROR::enum_warning_level level,
                         uint32_t code,
                         const char *format, ...);
void sql_reset_errors  (Session *session, bool force);

bool sqld_show_warnings(Session *session, uint32_t levels_to_show);

extern const LEX_STRING warning_level_names[];

#endif /* __SQL_ERROR_H__ */
